package code.example.base.reflect.instrospector;

import code.example.tool.LogFactory;
import org.springframework.core.MethodParameter;

import java.beans.*;
import java.lang.reflect.Method;

/**
 * beanInfo.getMethodDescriptors(); 没有啥用
 */
public class TestMethod {
    public void test() throws  Exception {
        BeanInfo beanInfo =  Introspector.getBeanInfo(SimpleBean.class);
        MethodDescriptor mds [] =  beanInfo.getMethodDescriptors();
        LogFactory.getLog().info(beanInfo.getBeanDescriptor().getName()+" methods:");
        PropertyDescriptor namePropertyDescriptor = null;
        for(int i=0;i<mds.length;i++){
            MethodDescriptor md = mds[i];
            String methodName = md.getName();
            if(methodName.equals("writeBook")){
                System.out.println();
            }

            ParameterDescriptor pds [] = md.getParameterDescriptors();
            StringBuilder sb = new StringBuilder("methodName:").append(methodName);
            if(pds != null){
                for(int j =0;j<pds.length;j++){
                    ParameterDescriptor pd = pds[i];
                    String parameterName = pd.getName();
                    sb.append("parameter").append(" ").append(j).append(":").append(parameterName);
                }
            }
            LogFactory.getLog().info(sb.toString());

        }

    }
    public static void main(String []args ){
        try {
            new TestMethod().test();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
